//
//  AllTableViewCell.m
//  DongChiDaChiProject1
//
//  Created by lanou3g on 15/10/30.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "AllTableViewCell.h"

@implementation AllTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addView];
    }
    return self;
}

// 添加视图
- (void)addView
{
    // 图片
    self.pictureImageV = [[UIImageView alloc] initWithFrame:CGRectMake(35 * kWidthFitParameter, 30 * kWidthFitParameter, 40 * kWidthFitParameter, 40 * kWidthFitParameter)];
    self.pictureImageV.userInteractionEnabled = YES;
   // self.pictureImageV.backgroundColor = [UIColor cyanColor];
    //self.pictureImageV.layer.cornerRadius = 12 * kWidthFitParameter;
    self.pictureImageV.layer.cornerRadius = self.pictureImageV.width / 2;

    self.pictureImageV.layer.masksToBounds = YES;
    [self.contentView addSubview:_pictureImageV];
    
    // 标题
    self.myTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.pictureImageV.left - 10 * kWidthFitParameter, self.pictureImageV.bottom + 10 * kWidthFitParameter, self.pictureImageV.width + 20 * kWidthFitParameter, 20 * kWidthFitParameter)];
    self.myTitleLabel.textAlignment = NSTextAlignmentCenter;
    self.myTitleLabel.font = [UIFont systemFontOfSize:15 * kWidthFitParameter];
    //  self.myTitleLabel.backgroundColor = [UIColor cyanColor];
    
    [self.contentView addSubview:_myTitleLabel];
    
    // 小箭头
    self.smallBoultLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.pictureImageV.right + 20 * kWidthFitParameter, self.pictureImageV.top + 30 * kWidthFitParameter, 15 * kWidthFitParameter, 18 * kWidthFitParameter)];
    self.smallBoultLabel.text = @">";
    self.smallBoultLabel.textColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:0.5];
    // self.smallBoultLabel.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:_smallBoultLabel];
    
    // 第一个button
    self.button1 = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button1.frame = CGRectMake(self.smallBoultLabel.right + 25 * kWidthFitParameter, 25 * kWidthFitParameter, 60 * kWidthFitParameter, 30 * kWidthFitParameter);
    self.button1.backgroundColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:0.1];
    self.button1.layer.cornerRadius = 5 * kWidthFitParameter;
    [self.button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.contentView addSubview:_button1];
    
    // 第二个button
    self.button2 = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button2.frame = CGRectMake(self.button1.right + 15 * kWidthFitParameter, 25 * kWidthFitParameter, 60 * kWidthFitParameter, 30 * kWidthFitParameter);
    [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.button2.backgroundColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:0.1];
    self.button2.layer.cornerRadius = 5 * kWidthFitParameter;
    [self.contentView addSubview:_button2];
    
    // 第三个button
    self.button3 = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button3.frame = CGRectMake(self.button2.right + 15 * kWidthFitParameter, 25 * kWidthFitParameter, 60 * kWidthFitParameter, 30 * kWidthFitParameter);
    [self.button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.button3.layer.cornerRadius = 5 * kWidthFitParameter;
    self.button3.backgroundColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:0.1];
    [self.contentView addSubview:_button3];
    
    // 第四个button
    self.button4 = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button4.frame = CGRectMake(self.button1.left,self.button1.bottom + 15 * kWidthFitParameter, 60 * kWidthFitParameter, 30 * kWidthFitParameter);
    [self.button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.button4.backgroundColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:0.1];
    self.button1.layer.cornerRadius = 5 * kWidthFitParameter;
    [self.contentView addSubview:_button4];
    
    // 第五个button
    self.button5 = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button5.frame = CGRectMake(self.button4.right + 15 * kWidthFitParameter, self.button4.top, 60 * kWidthFitParameter, 30 * kWidthFitParameter);
    [self.button5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.button5.backgroundColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:0.1];
    self.button5.layer.cornerRadius = 5 * kWidthFitParameter;
    [self.contentView addSubview:_button5];
    
    // 第六个button
    self.button6 = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button6.frame = CGRectMake(self.button5.right + 15 * kWidthFitParameter, self.button4.top, 60 * kWidthFitParameter, 30 * kWidthFitParameter);
    [self.button6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.button6.backgroundColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:0.1];
    self.button6.layer.cornerRadius = 5 * kWidthFitParameter;
    [self.contentView addSubview:_button6];
    
}

- (void)setFetchArray:(NSArray *)fetchArray
{
    switch (fetchArray.count) {
        case 1:
        {
            [self.button1 setTitle:[fetchArray[0] valueForKey:@"name"] forState:UIControlStateNormal];
            self.button2.hidden = YES;
            self.button3.hidden = YES;
            self.button4.hidden = YES;
            self.button5.hidden = YES;
            self.button6.hidden = YES;
            
            break;
        }
            case 2:
        {
            [self.button1 setTitle:[fetchArray[0] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button2 setTitle:[fetchArray[1] valueForKey:@"name"] forState:UIControlStateNormal];
            self.button3.hidden = YES;
            self.button4.hidden = YES;
            self.button5.hidden = YES;
            self.button6.hidden = YES;
            
            break;
        }
            case 3:
        {
            [self.button1 setTitle:[fetchArray[0] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button2 setTitle:[fetchArray[1] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button3 setTitle:[fetchArray[2] valueForKey:@"name"] forState:UIControlStateNormal];
            self.button4.hidden = YES;
            self.button5.hidden = YES;
            self.button6.hidden = YES;
            break;
        }
            case 4:
        {
            [self.button1 setTitle:[fetchArray[0] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button2 setTitle:[fetchArray[1] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button3 setTitle:[fetchArray[2] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button4 setTitle:[fetchArray[3] valueForKey:@"name"] forState:UIControlStateNormal];
            self.button5.hidden = YES;
            self.button6.hidden = YES;
            break;
        }
            case 5:
        {
            [self.button1 setTitle:[fetchArray[0] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button2 setTitle:[fetchArray[1] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button3 setTitle:[fetchArray[2] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button4 setTitle:[fetchArray[3] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button5 setTitle:[fetchArray[4] valueForKey:@"name"] forState:UIControlStateNormal];
            self.button6.hidden = YES;
            break;
        }
            case 6:
        {
            [self.button1 setTitle:[fetchArray[0] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button2 setTitle:[fetchArray[1] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button3 setTitle:[fetchArray[2] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button4 setTitle:[fetchArray[3] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button5 setTitle:[fetchArray[4] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button6 setTitle:[fetchArray[5] valueForKey:@"name"] forState:UIControlStateNormal];
            break;
        }
        default:
        {
            [self.button1 setTitle:[fetchArray[0] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button2 setTitle:[fetchArray[1] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button3 setTitle:[fetchArray[2] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button4 setTitle:[fetchArray[3] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button5 setTitle:[fetchArray[4] valueForKey:@"name"] forState:UIControlStateNormal];
            [self.button6 setTitle:[fetchArray[5] valueForKey:@"name"] forState:UIControlStateNormal];
            break;
        }
    }
//    if (fetchArray.count < 1) {
//        [self.button1 setTitle:@"" forState:UIControlStateNormal];
//        [self.button2 setTitle:@"" forState:UIControlStateNormal];
//        [self.button3 setTitle:@"" forState:UIControlStateNormal];
//        [self.button4 setTitle:@"" forState:UIControlStateNormal];
//        [self.button5 setTitle:@"" forState:UIControlStateNormal];
//        [self.button6 setTitle:@"" forState:UIControlStateNormal];
//        
//    } else {
//        [self.button1 setTitle:[fetchArray[0] valueForKey:@"name"] forState:UIControlStateNormal];
//        [self.button2 setTitle:[fetchArray[1] valueForKey:@"name"] forState:UIControlStateNormal];
//        [self.button3 setTitle:[fetchArray[2] valueForKey:@"name"] forState:UIControlStateNormal];
//        [self.button4 setTitle:[fetchArray[3] valueForKey:@"name"] forState:UIControlStateNormal];
//         [self.button5 setTitle:[fetchArray[4] valueForKey:@"name"] forState:UIControlStateNormal];
//         [self.button6 setTitle:[fetchArray[5] valueForKey:@"name"] forState:UIControlStateNormal];
//    }
   
   
    
    
}

- (void)setTitleString:(NSString *)titleString
{
    self.myTitleLabel.text = titleString;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
